package prodcon;

public class CircularBuffer3 {
	private static final int MAX_SIZE = 8;
	private int base = 0;
	private int[] circBuffer = new int[MAX_SIZE];
	private int size = 0;
	
	public int getValueFromBuffer() {
		int index = base;
		synchronized(this) {
			base = (base + 1) % MAX_SIZE;
			size--;
			return circBuffer[index];
		}
	}

	public void putValueIntoBuffer(int value) {
		int index;
		synchronized(this) {
			index = (base + size) % MAX_SIZE;
			size++;
			circBuffer[index] = value;
		}
	}

	public int get() { return getValueFromBuffer(); }
	
	public void put(int value) { putValueIntoBuffer(value); }
}
